package org.gpp.proj1.ui.gui.command;

import org.gpp.proj1.ui.gui.SRGGUIView;

/**
 * Class that creates SRGGUICommands for the GUI  
 * 
 * @author Paolo Victor, paolovictor@gmail.com
 */
public class SRGGUICommandFactory {

	/**
	 * Identifier for the "Load player profile" command
	 */
	public static final String LOAD_PROFILE = "loadProfile";
	
	/**
	 * Identifier for the "Cancel player profile loading" command
	 */
	public static final String CANCEL_PROFILE_LOADING = "cancelProfileLoading";

	/**
	 * Identifier for the "Create player profile" command
	 */
	public static final String CREATE_PROFILE = "createProfile";

	/**
	 * Identifier for the "Initialize part shop" command
	 */
	public static final String OPEN_PART_BUYER_WINDOW_COMMAND = "partShopCommand";
	
	/**
	 * Identifier for the "Initialize robot editor" command
	 */
	public static final String ROBOT_EDITOR_COMMAND = "robotEditorCommand";

	/**
	 * Identifier for the "Buy part" command
	 */
	public static final String BUY_PART_COMMAND = "buyPartCommand";

	/**
	 * Identifier for the "Initialize robot creator" command
	 */
	public static final String OPEN_ROBOT_CREATOR_COMMAND = "newRobotCommand";

	/**
	 * Identifier for the "Save robot" command
	 */
	public static final String SAVE_ROBOT_COMMAND = "saveRobotCommand";

	/**
	 * Identifier for the "Initialize robot editor" command
	 */
	public static final String OPEN_ROBOT_EDITOR_COMMAND = "editRobotCommand";

	/**
	 * Identifier for the "Delete robot" command
	 */
	public static final String DELETE_ROBOT_COMMAND = "deleteRobotCommand";

	public static final String OPEN_PART_SELLER_WINDOW_COMMAND = "openPartSeller";

	public static final String OPEN_PART_INVENTORY_WINDOW_COMMAND = "openPartInventory";

	public static final String START_GAME_COMMAND = "startGame";
	
	/**
	 * Builds and returns a command given its id and a parent view
	 * 
	 * @param view The view that will be the command's parent
	 * @param commandId The command identifier
	 * 
	 * @return Th
	 */
	public static SRGGUICommand createCommand( SRGGUIView view, String commandId ) {
		if( view == null ) {
			throw new IllegalArgumentException( "null parent view" );
		}
		if( commandId == null ) {
			throw new IllegalArgumentException( "null command identifier" );
		}
		
		SRGGUICommand command = null;
		
		if( commandId.equals( CREATE_PROFILE ) ) {
			command = new CreateProfileCommand( view );
		} else if( commandId.equals( LOAD_PROFILE ) ) {
			command = new LoadProfileCommand( view );
		} else if( commandId.equals( CANCEL_PROFILE_LOADING ) ) {
			command = new CancelProfileLoadingCommand( view );
		} else if( commandId.equals( OPEN_PART_BUYER_WINDOW_COMMAND ) ) {
			command = new ShowPartShopCommand( view );
		} else if( commandId.equals( BUY_PART_COMMAND ) ) {
			command = new BuyPartCommand( view );
		} else if( commandId.equals( ROBOT_EDITOR_COMMAND ) ) {
			command = new ShowRobotEditorCommand( view );
		} else if( commandId.equals( OPEN_ROBOT_CREATOR_COMMAND ) ) {
			command = new OpenRobotCreatorCommand( view );
		} else if( commandId.equals( OPEN_ROBOT_EDITOR_COMMAND ) ) {
			command = new OpenRobotEditorCommand( view );
		} else if( commandId.equals( SAVE_ROBOT_COMMAND ) ) {
			command = new SaveRobotCommand( view );
		} else if( commandId.equals( DELETE_ROBOT_COMMAND ) ) {
			command = new DeleteRobotCommand( view );
		} else if( commandId.equals( START_GAME_COMMAND ) ) {
			command = new StartGameCommand( view );
		}
		
		if( commandId == null ) {
			throw new IllegalArgumentException( "Invalid command identifier: \"" + commandId + "\"" );
		} 
		return command;
	}
}
